package util.lang.sql;

import java.util.LinkedList;

public class SqlSingleOrderByStatement extends SqlOrderByStatement {
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	
	private String tableName;
	private String columeName;
	private boolean ascendOrder;
	
	public String getTableName() {
		return this.tableName;
	}
	public void setTableName(String tableName) {
		this.tableName = tableName;
	}

	public String getColumeName() {
		return this.columeName;
	}
	public void setColumeName(String columeName) {
		this.columeName = columeName;
	}

	public boolean isAscendOrder() {
		return this.ascendOrder;
	}
	public void setAscendOrder(boolean ascendOrder) {
		this.ascendOrder = ascendOrder;
	}
	
	public SqlSingleOrderByStatement() {
		this.tableName = "";
		this.columeName = "";
		this.ascendOrder = true;
	}
	public SqlSingleOrderByStatement(String columnName) {
		this.tableName = "";
		this.columeName = columnName;
		this.ascendOrder = true;
	}
	public SqlSingleOrderByStatement(String tableName, String columnName) {
		this.tableName = tableName;
		this.columeName = columnName;
		this.ascendOrder = true;
	}
	public SqlSingleOrderByStatement(String columnName, boolean ascendOrder) {
		this.tableName = "";
		this.columeName = columnName;
		this.ascendOrder = ascendOrder;
	}
	public SqlSingleOrderByStatement(String tableName, String columnName, boolean ascendOrder) {
		this.tableName = tableName;
		this.columeName = columnName;
		this.ascendOrder = ascendOrder;
	}
	
	@Override
	public String getSql() {
		return " ORDER BY " + getSqlNoOrderBy();
	}
	
	public String getSqlNoOrderBy() {
		StringBuffer sb = new StringBuffer();
		if (tableName != null && !"".equals(tableName)) {
			sb.append(tableName);
			sb.append('.');
		}
		sb.append(columeName);
		sb.append(' ');
		if (ascendOrder)
			sb.append("ASC");
		else
			sb.append("DESC");
		return sb.toString();
	}
	
	@Override
	public LinkedList<Object> getValues() {
		return new LinkedList<Object>();
	}
	
	@Override
	public String toString() {
		return getSql();
	}
}
